﻿namespace iFinance.Infrastructure.Converters
{
    using System;
    using System.Windows.Data;

    /// <summary>
    /// Bool值取反
    /// </summary>
    public class NegateBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                bool source;
                if (bool.TryParse(value.ToString(), out source))
                {
                    return !source;
                }
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                bool source;
                if (bool.TryParse(value.ToString(), out source))
                {
                    return !source;
                }
            }
            return value;
        }
    }
}
